<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  {
    // 放
    let cz = [1, 2, 3];
    let [a, b, c] = [...cz];

    // 收
    let [i, ...arr] = [2, 4, 7, 8, 9];
    console.log(i);
    console.log(arr);
  }; {
    let sum = (...arg) => { //实现求和
      return arg.reduce((pre, value, index, array) => {
        console.log(pre, value);
        return pre + value;
      }, 0);
    };

    let arr = [];
    let s = sum(2, 2, 3);
    console.log(s);
  }; {
    // 有其它参数时，要扩展运算符要放在后面
    let sum = function (discount = 0, ...price) { //商品打折案例
      let total = price.reduce((a, b) => a + b);
      console.log(total);
      return Math.round(total * (1 - discount)); //算折扣
    };
    console.log(sum(0.8, 199, 1, 0));
  }
</script>

</html>